<!--
  - Copyright 2011 Angel Sanadinov
  -
  - This file is part of VBox WMI.
  -
  - VBox WMI is free software: you can redistribute it and/or modify
  - it under the terms of the GNU General Public License as published by
  - the Free Software Foundation, either version 3 of the License, or
  - (at your option) any later version.
  -
  - VBox WMI is distributed in the hope that it will be useful,
  - but WITHOUT ANY WARRANTY; without even the implied warranty of
  - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  - GNU General Public License for more details.
  -
  - You should have received a copy of the GNU General Public License
  - along with VBox WMI.  If not, see <http://www.gnu.org/licenses/>.
  -->

<%@tag description="put the tag description here" pageEncoding="UTF-8" trimDirectiveWhitespaces="true"%>
<%@tag import="Beans.Responses.DataRetrievalComponents.LogDataComponent"%>
<%@tag import="Beans.Responses.DataRetrievalResponse"%>
<%@tag import="Utilities.Constants.ResourceRequestType"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="jstlc"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="jstlfn"%>

<%-- Attributes --%>
<%@attribute name="data" required="true" description="Logs data response object."
             rtexprvalue="true" type="DataRetrievalResponse<LogDataComponent>"%>
<%-- End of Attributes --%>

<%-- Page Body Content --%>
<jstlc:choose>
    <jstlc:when test="${data == null}">
        Failed to retrieve logs data object.
    </jstlc:when>

    <jstlc:when test="${data.requestResult && data.valid}">
        <jstlc:choose>
            <jstlc:when test="<%= data.getResourceRequestType() == ResourceRequestType.MULTIPLE_RESOURCES
                    && data.getResourcesList().size() > 0 %>">
                <table id="logsTable" class="resourcesTable">
                    <tr><td>User ID</td><td>Server ID</td><td>Event ID</td><td>Severity</td><td>Date</td><td>Description</td></tr>
                    <jstlc:forEach var="log" items="${data.resourcesList}">
                        <tr><td><a href="users.jsp?id=${log.logData.initiatorId}">${log.logData.initiatorId}</a></td>
                            <td><a href="servers.jsp?id=${log.logData.serverId}">${log.logData.serverId}</a></td>
                            <td>${log.logData.eventId}</td><td>${log.logData.severity}</td><td>${log.logData.eventDate}</td>
                            <td>${log.logData.description}</td></tr>
                    </jstlc:forEach>
                </table>
                <script type="text/javascript">
                    var logsPagination = new ElementsTablePagination('logsTable', 'logsPagination');
                </script>
                Page Size: <input type="text" size="2" id="itemsPerPage" value="20">
                <a class="pageSizeUpdateLink" href="noJavaScript.jsp"
                   onclick="return logsPagination.setMaxNumberOfItemsPerPage(document.getElementById('itemsPerPage').value);">Update</a>
            </jstlc:when>

            <jstlc:when test="${jstlfn:length(data.resourcesList) <= 0}">
                No data is available.
            </jstlc:when>
                
            <jstlc:otherwise>
                Invalid resource request type: ${data.resourceRequestType}.
            </jstlc:otherwise>
        </jstlc:choose>
    </jstlc:when>

    <jstlc:otherwise>
        ${data.exception.exceptionMessage}
    </jstlc:otherwise>
</jstlc:choose>
<%-- End of Page Body Content --%>